﻿using System;

namespace Limestone.Fields
{
    [Serializable]
    public class PageField : Field, IField
    {
        public string Path { get; set; }

        public new PageFieldSetting Settings
        {
            get { return base.Settings as PageFieldSetting; }
            set { base.Settings = value; }
        }

        public PageField()
            : base(FieldType.PageField, "")
        {
            Path = "";
        }

        public PageField(string name)
            : base(FieldType.PageField, name)
        {
            Path = "";
        }


        public string GetHtml()
        {
            return "<a href=\"" + Path + "\">" + Path + "</a>";
        }

        public string GetLink(PageStubCache pageStubCache)
        {
            var linkedPage = pageStubCache.GetPageStub(Path);
            if (linkedPage != null)
            {
                return "<a href=\"" + linkedPage.Path + "\">" + linkedPage.Title + "</a>";
            }
            return "";
        }

    }
}
